package com.lanwf.admin.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.lanwf.common.model.SysConfig;
import com.lanwf.admin.utils.CommonUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @Auther: Lanwf
 * @Date: 2021/12/23 17:57
 * @Description:
 */
public class AdminConfigInterceptor implements Interceptor {

    @Override
    public void intercept(Invocation inv) {
        Controller c = inv.getController();


        SysConfig config = (SysConfig)CommonUtil.getCache("config");
        if(config == null){
            config = SysConfig.dao.findById(1);

            if(config !=null && StringUtils.isNotBlank(config.getPrjDesc())){
                String[] split = config.getPrjDesc().split("[;；]");
                ArrayList<String> desc = new ArrayList<>(Arrays.asList(split));
                config.put("list",desc);
            }

            CommonUtil.setCache("config",config);
        }
        c.set("config",config);
        inv.invoke();
    }

}
